//
//  WifiHotSpotListViewController.m
//  ForYourBeauty
//
//  Created by Kelly xu on 2019/8/23.
//  Copyright © 2019 changrenTech. All rights reserved.
//

#import "WifiHotSpotListViewController.h"
#import <NetworkExtension/NEHotspotHelper.h>
@interface WifiHotSpotListViewController ()

@end

@implementation WifiHotSpotListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    NSMutableDictionary* options = [[NSMutableDictionary alloc] init];
    [options setObject:@"我叫谷子就是这么屌" forKey:kNEHotspotHelperOptionDisplayName];
    dispatch_queue_t queue = dispatch_queue_create("com.myapp.ex", NULL);
    //注册成功会返回一个Yes值，否则No
    BOOL returnType = [NEHotspotHelper registerWithOptions:options queue:queue handler: ^(NEHotspotHelperCommand * cmd) {
        NEHotspotNetwork* network;
        if (cmd.commandType == kNEHotspotHelperCommandTypeEvaluate || cmd.commandType ==kNEHotspotHelperCommandTypeFilterScanList) {
            for (network  in cmd.networkList) {
                NSLog(@"COMMAND TYPE After:   %ld", (long)cmd.commandType);
                NSLog(@"SSID-> %@ Mac地址-> %@ 信号强度-> %f",network.SSID,network.BSSID,network.signalStrength);
                if ([network.SSID isEqualToString:@"免费WiFi"]) {
                    double signalStrength = network.signalStrength;
                    NSLog(@"Signal Strength: %f", signalStrength);
                    [network setConfidence:kNEHotspotHelperConfidenceHigh];
                    [network setPassword:@"xxxxxxx"];
                    NEHotspotHelperResponse *response = [cmd createResponse:kNEHotspotHelperResultSuccess];
                    NSLog(@"Response CMD %@", response);
                    [response setNetworkList:@[network]];
                    [response setNetwork:network];
                    [response deliver];
                }
            }
        }
    }];
    NSLog(@")_________________________________%d",returnType);
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
